import request from '@/utils/request'

export function login(data, tenantId) {
  return request({
    url: '/login',
    method: 'post',
    data,
    transformRequest: [function(data) {
      let ret = ''
      for (const item in data) {
        ret += encodeURIComponent(item + '') + '=' + encodeURIComponent(data[item + '']) + '&'
      }
      ret = ret.substring(0, ret.length - 1)
      return ret
    }],
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'TENANT_ID': tenantId || ''
    }
  })
}

export function getInfo() {
  return request({
    url: '/users/info',
    method: 'get'
  })
}

export function getUserList(params) {
  return request({
    url: '/users/page',
    method: 'get',
    params: params
  })
}

export function saveUser(data) {
  return request({
    url: '/users',
    method: 'post',
    data
  })
}

export function updateUser(data) {
  return request({
    url: '/users',
    method: 'put',
    data
  })
}

export function deleteUser(id) {
  return request({
    url: '/users/' + id,
    method: 'delete'
  })
}

export function logout() {
  return request({
    url: '/user/logout',
    method: 'post'
  })
}
